package com.alex.rankingpoint;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/rank")
public class Alex008ScoreRankController {

    @Autowired
    private Alex008ScoreRankService rankService;

    // 增加或更新用户积分
    @PostMapping("/score")
    public String updateScore(
            @RequestParam String userId,
            @RequestParam long score) {
        rankService.updateScore(userId, score);
        return "ok";
    }

    // 查询排行榜TopN
    @GetMapping("/top")
    public List<Map<String, Object>> getTopN(
            @RequestParam(defaultValue = "10") int n) {
        return rankService.getTopN(n);
    }

    // 查询某用户的排名与积分
    @GetMapping("/user")
    public Map<String, Object> getUserRankInfo(
            @RequestParam String userId) {
        return rankService.getUserRankInfo(userId);
    }

    // 删除某用户记录
    @DeleteMapping("/user")
    public String removeUser(@RequestParam String userId) {
        rankService.removeUser(userId);
        return "ok";
    }
}